package PersonInformation;

public class PersonInformationListUse {
        PersonInformation[] per;
        int total;
        //构造器中初始化数组容量
        public PersonInformationListUse(int totalCapacity){
                per=new PersonInformation[totalCapacity];
        }
        //添加元素
        public boolean addList(PersonInformation newPer){
                if(total>=per.length){
                        return false;
                }else{
                        per[total++]=newPer;
                        return true;
                }

        }
        //删除指定下标元素
        public boolean deleteElem(int index){

                if(total>=per.length){
                        return false;
                }else{
                        for(int i=index;i<total-1;i++){
                                per[i]=per[i+1];
                        }
                        per[total--]=null;
                        return true;
                }
        }
        //更改元素
        public boolean replace(int index ,PersonInformation newPer){
                        if(index<0||index>=total){
                                return false;
                        }else{
                                per[index]=newPer;
                                return true;
                        }
        }
        //查找单个元素
        public PersonInformation getPer(int index){
                        if(index<0||index>=total){
                                return null;
                        }else{
                                return per[index];
                        }
        }
        //查找所有元素
        public PersonInformation[] getAllElem(){
                PersonInformation[] Per=new PersonInformation[total];
                for(int i=0;i<total;i++){
                        Per[i]=per[i];
                }
                return Per;
        }
        //获取数组大小
        public int getTotal(){
                return total;
        }

}
